//将URL中的UTF-8字符串转成中文字符串
function getCharFromUtf8(str) {
	var cstr = "";
	var nOffset = 0;
	if (str == "")
		return "";
	str = str.toLowerCase();
	nOffset = str.indexOf("%e");
	if (nOffset == -1)
		return str;
	while (nOffset != -1) {
		cstr += str.substr(0, nOffset);
		str = str.substr(nOffset, str.length - nOffset);
		if (str == "" || str.length < 9)
			return cstr;
		cstr += utf8ToChar(str.substr(0, 9));
		str = str.substr(9, str.length - 9);
		nOffset = str.indexOf("%e");
	}
	return cstr + str;
}

//将编码转换成字符
function utf8ToChar(str) {
	var iCode, iCode1, iCode2;
	iCode = parseInt("0x" + str.substr(1, 2));
	iCode1 = parseInt("0x" + str.substr(4, 2));
	iCode2 = parseInt("0x" + str.substr(7, 2));
	return String.fromCharCode(((iCode & 0x0F) << 12) | ((iCode1 & 0x3F) << 6) | (iCode2 & 0x3F));
}

//判断手机号是否正确
function isRightTel(input) {
	var tempInput = input;
	if (tempInput.match(/^1[3|4|5|8][0-9]{9}$/)) {
		return true;
	} else {
		return false;
	}
}

//判断邮箱是否正确
function isRightEmail(input) {
	var tempInput = input;
	if (tempInput.match(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/)) {
		return true;
	} else {
		return false;
	}
}

//判断姓名是否正确
function isRightName(input){
	var tempInput = input;
	if (tempInput.match(/[\u4E00-\u9FA5]/) || tempInput.match(/[a-zA-Z]/)) {
		return true;
	} else {
		return false;
	}
}

//判断是否是整数
function isRightMoney(input){
	var tempInput = input;
	if (tempInput.match(/^[0-9]*[1-9][0-9]*$/)) {
		return true;
	} else {
		return false;
	}
}

//重写alert方法
window.alert = function(txt,btnText,isBtnDisabled) {
	var shield = document.createElement("DIV");
	shield.id = "shield";
	shield.style.position = "absolute";
	shield.style.left = "0px";
	shield.style.top = "0px";
	shield.style.width = "100%";
	shield.style.height = document.body.scrollHeight + "px";
	shield.style.background = "#000";
	shield.style.opacity = "0.7";
	shield.style.textAlign = "center";
	shield.style.zIndex = "10000";
	shield.style.filter = "alpha(opacity=0)";
	var alertFram = document.createElement("DIV");
	alertFram.id = "alertFram";
	alertFram.style.position = "absolute";
	alertFram.style.left = "10%";
	alertFram.style.top = parseInt($("body").scrollTop() + 150) + "px";
//	alertFram.style.top = "0px";
	alertFram.style.marginLeft = "0px";
	alertFram.style.marginTop = "0px";
	alertFram.style.width = "80%";
	alertFram.style.height = "auto";
	alertFram.style.background = "#ccc";
	alertFram.style.textAlign = "center";
	alertFram.style.lineHeight = "150px";
	alertFram.style.zIndex = "10001";
	alertFram.style.display = "block";
	
	if (isBtnDisabled == 0) {
		strHtml = "<ul style=\"list-style:none;margin:0px;padding:0px;width:100%\">\n";
		strHtml += " <li style=\"background: #27ABFB;color:white;text-align:left;/* padding-left:20px; */font-size:15px;font-weight:bold;height: 40px;line-height: 40px;border-bottom: 1px solid #E8FFFC;text-align:center;font-weight:bold;font-size:15px;\">提&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;示</li>\n";
		strHtml += " <li style=\"background: #E8FFFC;color: black;font-family:'黑体';text-align:center;font-size: 16px;height: 50px;line-height: 50px;border-bottom: 1px solid #E8FFFC;word-wrap:break-word; word-break:normal;\">" + txt + "</li>\n";
		strHtml += " <li style=\"line-height: 20px;background-color: #E8FFFC;\"><button style=\"width: 50%;font-size: 15px;padding-top: 5px;padding-bottom: 5px;margin-top: 0px;margin-bottom: 15px;background-color: #C2FFFF;color: #4D4D4D;border-radius: 5px;border: 1px solid #0084BF;font-weight: bold;\" onclick=\"doOk()\">"+btnText+"</button></li>\n";
	} else {
		strHtml = "<ul style=\"list-style:none;margin:0px;padding:0px;width:100%\">\n";
		strHtml += " <li style=\"background: #27ABFB;color:white;text-align:left;/* padding-left:20px; */font-size:15px;font-weight:bold;height: 40px;line-height: 40px;border-bottom: 1px solid #E8FFFC;text-align:center;font-weight:bold;font-size:15px;\">提&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;示</li>\n";
		strHtml += " <li style=\"background: #E8FFFC;color: black;font-family:'黑体';text-align:center;font-size: 16px;height: 50px;line-height: 50px;border-bottom: 1px solid #E8FFFC;word-wrap:break-word; word-break:normal;\">" + txt + "</li>\n";
		strHtml += " <li style=\"line-height: 20px;background-color: #E8FFFC;display:none;\"><button style=\"width: 50%;font-size: 15px;padding-top: 5px;padding-bottom: 5px;margin-top: 0px;margin-bottom: 15px;background-color: #C2FFFF;color: #4D4D4D;border-radius: 5px;border: 1px solid #0084BF;font-weight: bold;\" onclick=\"doOk()\">"+btnText+"</button></li>\n";
	}
	
	strHtml += "</ul>\n";
	alertFram.innerHTML = strHtml;
	document.body.appendChild(alertFram);
	document.body.appendChild(shield);
	$("#alertFram").css({"-webkit-animation":"dialogAnimate .5s"});
	
	var c = 0;
	this.doAlpha = function() {
		if (c++ > 20) {
			clearInterval(ad);
			return 0;
		}
		shield.style.filter = "alpha(opacity=" + c + ");";
	}
	var ad = setInterval("doAlpha()", 5);
	this.doOk = function() {
		$("#alertFram").remove();
		$("#shield").remove();
	}
	alertFram.focus();
	document.body.onselectstart = function() {
		return false;
	};
}

//弹框消失
function alertFade(){
	$("#alertFram").remove();
	$("#shield").remove();
}

//背景蒙版
function shield(){
	var shield = document.createElement("DIV");
	shield.id = "myShield";
	shield.style.position = "absolute";
	shield.style.left = "0px";
	shield.style.top = "0px";
	shield.style.width = "100%";
	shield.style.height = document.body.scrollHeight + "px";
	shield.style.background = "#000";
	shield.style.opacity = "0.7";
	shield.style.textAlign = "center";
	shield.style.zIndex = "10000";
	shield.style.filter = "alpha(opacity=0)";
	document.body.appendChild(shield);
}

//蒙版消失
function shieldFade(){
	$("#myShield").remove();
}